package com.itheima.advantagesup.controller;


import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.entity.SysMenu;
import com.itheima.advantagesup.dto.SysMenuDto;
import com.itheima.advantagesup.service.SysMenuService;
import com.itheima.advantagesup.vo.MenuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sys_menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysmenuService;


    /**
     * 获得所有菜单
     * @return {@link R}
     */
    @GetMapping("/allData")
    public R getAll(){
        log.info("获得所有菜单");
        List<MenuVO> menuVO = sysmenuService.getAll();
        return R.success(menuVO);
    }

    @PostMapping("/add")
    public R add(@RequestBody SysMenuDto sysMenuDto){
        log.info("添加菜单新成员:{}",sysMenuDto);
        sysmenuService.add(sysMenuDto);
        return R.success();
    }

    @GetMapping("/del")
    public R delete(String id){
        log.info("删除菜单根据id:{}",id);
        sysmenuService.delete(id);
        return R.success();
    }

    @PostMapping("/update")
    public R update(@RequestBody SysMenuDto sysMenuDto){
        log.info("根据id修改数据:{}",sysMenuDto.getId());
        sysmenuService.update(sysMenuDto);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R findById(String id){
        log.info("查询菜单根据数据:{}",id);
        SysMenu sysMenu = sysmenuService.findById(id);
        return R.success(sysMenu);
    }
}
